package components.custom
{
	import flash.events.Event;

	public class CheckBoxItemRenderer extends CenterAlignCheckBox
	{
		public static const CHANGE_CHECKED_STATUS:String = "changeCheckedStatus";
		
		public function CheckBoxItemRenderer()
		{
			super();
			addEventListener(Event.CHANGE, changeHandler);
		}
		
		override public function dispose():void
		{
			removeEventListener(Event.CHANGE, changeHandler);
		}
		
		override public function set data(value:Object):void
		{
			super.data = value;
			if(value && value.hasOwnProperty("checked") 
				&& value.checked != selected)
				selected = value.checked;
		}
		
		/**
		 * 点击check box时，根据状况向selectedItems array中添加当前行的引用，或者从array中移除
		 * @param evt
		 * */
		private function changeHandler(evt:Event):void
		{
			if(data.hasOwnProperty("checked"))
				data.checked = selected; //根据是否选中的状态，更改数据源中选中的标记
			dispatchEvent(new Event(CHANGE_CHECKED_STATUS, true));
		}
	}
}